package arg

import (
	"encoding/json"
	"fmt"
	"db2s/global"
	"reflect"
	"strings"
)

type indexLevel struct {
	BreakPoint bool `json:"breakpoint"`
}

// structRuleSecondaryLevelParameterCheck
func (rc *ConfigParameter) indexRuleSecondaryLevelParameterCheck(checkMod string) error {
	var (
		indexMap map[string]any
		err      error
		f3       = rc.FirstL1.Rules.ToConfig().GetObject(rc.getObjectName(checkMod)).ToConfig()
	)
	rc.SecondaryL.RulesV.CheckMode = rc.getObjectName(checkMod)
	rc.SecondaryL.FunctionalMode = rc.getObjectName(checkMod)
	if indexMap, err = global.StructToMapAny(getIndexRules()); err != nil {
		return err
	}
	var s2 []string
	for k, v := range indexMap {
		if r1 := rc.getHoconConfigVal(f3, k, reflect.TypeOf(v).String()); r1 != nil {
			s2 = append(s2, rc.anyToJsonString(k, r1))
		} else {
			s2 = append(s2, rc.anyToJsonString(k, v))
		}
	}
	if err = json.Unmarshal([]byte(strings.ReplaceAll(fmt.Sprintf("{%s}", strings.Join(s2, ",")), "\\", "\\\\")), &rc.SecondaryL.RulesV.Index); err != nil {
		return err
	}
	return nil
}

func indexParameterCheck(s *SecondaryLevel) error {
	return nil
}
